﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VideoFlowTagger
{
	/// <summary>
	/// A UTC object should be used to represent time and date. The overriden
	/// ToString() method will format the data in the following format:
	/// <code>2010-08-27T09:00:00Z</code>
	/// </summary>
    public struct UTC
    {
        private int? Year;
        private int? Month;
        private int? Day;

        private int? Hours;
        private int? Minutes;
        private int? Seconds;

        public UTC(int year, int month, int day)
        {
            this.Year = year;
            this.Month = month;
            this.Day = day;

            this.Hours = 0;
            this.Minutes = 0;
            this.Seconds = 0;
        }

        public UTC(int year, int month, int day, int hours, int minutes, int seconds)
        {
            this.Year = year;
            this.Month = month;
            this.Day = day;

            this.Hours = hours;
            this.Minutes = minutes;
            this.Seconds = seconds;
        }

        public UTC(string value)
        {
            int length = value.Length;
            if (length > 10)
            {
                Year = int.Parse(value.Substring(0, 4));
                Month = int.Parse(value.Substring(5, 2));
                Day = int.Parse(value.Substring(8, 2));
                Hours = int.Parse(value.Substring(12, 2));
                Minutes = int.Parse(value.Substring(15, 2));
                Seconds = int.Parse(value.Substring(18, 2));
            }
            else if (length > 4)
            {
                Year = int.Parse(value.Substring(0, 4));
                Month = int.Parse(value.Substring(5, 2));
                Day = int.Parse(value.Substring(8, 2));
                Hours = 0;
                Minutes = 0;
                Seconds = 0;
            }
            else if (length == 4)
            {
                Year = int.Parse(value.Substring(0, 4));
                Month = 0;
                Day = 0;
                Hours = 0;
                Minutes = 0;
                Seconds = 0;
            }
            else
            {
                Year = 0;
                Month = 0;
                Day = 0;
                Hours = 0;
                Minutes = 0;
                Seconds = 0;
            }
        }

        public override string ToString()
        {
            return Year.Value.ToString("0000") + "-" +
                   Month.Value.ToString("00") + "-" +
                   Day.Value.ToString("00") + "T" +
                   Hours.Value.ToString("00") + ":" +
                   Minutes.Value.ToString("00") + ":" +
                   Seconds.Value.ToString("00") + "Z";
        }
    }
}
